package com.dingli.service.impl;

import com.dingli.framework.entity.Member;
import com.dingli.framework.entity.User;
import com.dingli.framework.mapper.MemberMapper;
import com.dingli.framework.util.Response;
import com.dingli.service.IMemberService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberService implements IMemberService {

    @Autowired
    private MemberMapper memberMapper;

    @Override
    public Response<PageInfo<Member>> MBlist(String search, Integer pageNum, Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;
        }
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Member> info = new PageInfo<>(memberMapper.MBlist(search));
        return new Response<>(200, "success", info);
    }

    @Override
    public Response<Long> MBinsert(Member member) {
        int count = memberMapper.MBinsert(member);
        if (count > 0) {
            return new Response(200, "success", member.getMbId());
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Member> MBselectById(Long mdID) {
        return new Response(200, "success", memberMapper.MBselectById(mdID));
    }

    @Override
    public Response<Object> MBupdateById(Member member) {
        int count = memberMapper.MBupdateById(member);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> MBdeleteById(Long mbID) {
        int count = memberMapper.MBdeleteById(mbID);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<List<Member>> selectArea(String mbEseprovince) {
        return new Response<>(200,"success", memberMapper.selectArea(mbEseprovince));
    }

    /*@Override
    public Response<List<Member>> selectName(String mbCompany) {
        return new Response<>(200,"success", memberMapper.selectName(mbCompany));
    }*/

    @Override
    public Response<Object> updateState(String mbId) {
        int count = memberMapper.updateState(mbId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> update(String mbId) {
        int count = memberMapper.update(mbId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<List<Member>> selectState(String mbState) {
        List<Member> members = memberMapper.selectState(mbState);
        return new Response<>(200,"success", memberMapper.selectState(mbState));
    }

    @Override
    public Response<List<Member>> selectState1(String mbState) {
        List<Member> members = memberMapper.selectState1(mbState);
        return new Response<>(200,"success", memberMapper.selectState1(mbState));
    }

    @Override
    public Response<List<Member>> All(String mbId) {
        return new Response<>(200,"success", memberMapper.All(mbId));
    }


}

